package com.pt.chitra.facade
{
	
	import com.pt.chitra.appCommands.ApplicationStartupCommand;
	import com.pt.chitra.view.mainAppView.MainViewMediator;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.IProxy;
	import org.puremvc.as3.patterns.facade.Facade;

	public class ApplicationFacade extends Facade
	{
		public static const APP_STARTUP: String = "appStartup";
		
		/**
		*Added By : Skulkarni
		*Date : 15 Feb 2010
		*Desc : Application ref. required for view ref. 
		*/
		public var FRMApplication:PManager;
							
		public static function getInstance(): ApplicationFacade
		{
			if (instance == null) instance = new ApplicationFacade();
			return instance as ApplicationFacade;
		}
	
		override protected function initializeController() : void 
		{
			super.initializeController();		
			registerCommand( APP_STARTUP, ApplicationStartupCommand);
		}
	
		public function startup( application:PManager ):void
		{
			FRMApplication =  application;
			 this.sendNotification( ApplicationFacade.APP_STARTUP, application );
			this.registerMediator( new MainViewMediator( application.mainView)); 
			
		}
		
		/**
		*Added By : Skulkarni
		*Date : 04 May 2009
		*Desc : Gloabal Check for Proxy, returns boolean 
		*/
		public static function checkProxyRegistration(proxyName:String, proxyObject:IProxy):Boolean{
			var proxyRegistration:Boolean=false;
			if(!ApplicationFacade.getInstance().hasProxy(proxyName)){
				ApplicationFacade.getInstance().registerProxy(proxyObject);
				proxyRegistration = true;
			}
			return proxyRegistration;
		}
		
		/**
		*Added By : Skulkarni
		*Date : 05 May 2009
		*Desc : Gloabal Check for Command, returns boolean 
		*/	
		public static function checkCommandRegistration(commandName:String,commandClass:Class):Boolean{
			var commandRegistration:Boolean=false;
			if(!ApplicationFacade.getInstance().hasCommand(commandName)){
				ApplicationFacade.getInstance().registerCommand(commandName,commandClass);
				commandRegistration=true
			}
			return commandRegistration;
		} 
		
		public static function checkMediatorRegistration(checkMediator:IMediator):void{
			
			if(!ApplicationFacade.getInstance().hasMediator(checkMediator.getMediatorName())){
				ApplicationFacade.getInstance().registerMediator(checkMediator);
			}
			
		}
		
			
		}
		
	 }
			
